<?php

  class DailiAction extends CommonAction{
  
    public function index(){
	
	  if(isset($_GET['keywords'])){
	  
	    $this->keyword=$_GET['keywords'];
		
		$keyword=$_GET['keywords'];
		
		$where['username']=array("LIKE","%$keyword%");
	  
	  }
	  
	  $where['type']=array('eq',1);
	  if(isset($_GET['yingyee'])){
	  
	     if($_GET['yingyee']==1){
	  
	      $re=$this->page('dailiuser','10','id desc',$where);
		 }
		  
	  
	  }else{
	  
	  
		$re=$this->page('dailiuser','10','id desc',$where);
	 
	 } 
	  
	  $i=-1;
	  foreach($re as $v){
      $i++;
	  
	    $up=M('dailiuser')->where('id="%s"',$v['upid'])->find();	  
	    
		$re[$i]['upname']=$up['username'];
		
		$fenxiao=M('dailiuser')->where('id="%s"',$v['fenxiaoid'])->field('username')->find();
		
		$re[$i]['fenxiaoname']=$fenxiao['username'];
		
	  
	  }
	  
      	
	  $this->re=$re;	
		
	  $this->display();
	
	}
	
	
	public function yanzheng(){
	
	   $re=M('yanzheng')->where('id=1')->find();
	
	   if($re['yanzheng']==$_POST['yanzheng']){
	   
	     $ajax=1;
	   }else{
	   
	     $ajax=2;
	   
	   }
	
	   $this->ajaxReturn($ajax);
	
	}
	
	
	
	public function tixian(){
	
	  if(isset($_GET['start'])){
	  
	      $this->start=$_GET['start'];
		  $this->end=$_GET['end'];
	  
	      $start=strtotime($_GET['start']);
	  
	      $end=strtotime($_GET['end']);
	  
	      if($start>$end){
		  
		    $this->error('开始时间不能大于结束时间');
		  
		  }
		  $end=$end+86400;
		  
		  
		  $where['time']=array(array('gt',$start),array('lt',$end),'and');
	  
	  
	  }
	
	  $where['tixianid']=array('eq',$_GET['id']);
	  
	  $re=$this->page('tixian','10','id desc',$where);
	  
	  $this->re=$re;
	  
	   if(isset($_GET['start'])){
	     
		  $total=M('tixian')->where($where)->select();
		  $money=0;
		  foreach($total as $v){
		  
		    $money+=$v['money'];
		  
		  }
	   
	       $this->money=$money;
	   
	   }
	
	  $this->display();
	
	}
  
  
    public function del(){
	
	  $this->ajaxReturn((M('dailiuser')->where('id="%s"',$_POST['id'])->delete())?1:2);
	
	}
  
  
    public function jibie(){
	  $where['id']=array('eq','1');
	  
	  if(!empty($_POST)){
	  
	    $re=M('yongjin')->where($where)->save($_POST);
		
		if($re!==false){
		
		  $this->success('设置成功');exit();
		
		}else{
		
		  $this->error('设置失败');
		
		}
	  
	  }
	  
	  
	  $this->re=M('yongjin')->where($where)->find();
	  
	  $this->display();
	
	}
	
	
	public function yingyee(){
	
	
	  if(isset($_GET['start'])){
	  
	      $this->start=$_GET['start'];
		  $this->end=$_GET['end'];
	  
	      $start=strtotime($_GET['start']);
	  
	      $end=strtotime($_GET['end']);
	  
	      if($start>$end){
		  
		    $this->error('开始时间不能大于结束时间');
		  
		  }
		  $end=$end+86400;
		  
		  
		  $where['time']=array(array('gt',$start),array('lt',$end),'and');
	  
	  }
	
	
	  $where['uid']=array('eq',$_GET['id']);
	  
	  $where['status']=array('eq','1');
	 
	  $re=$this->page('buyer','10','id desc',$where);
	  
	 
	  
	    
		$i=-1;
		
		foreach($re as $v){
		  
		  $i++;
		  
		  $pianku=M('pianku')->where('id="%s"',$v['vid'])->field('title')->find();
		  
		  
		  
		  $re[$i]['title']=$pianku['title'];
		
		}
	  
	  
	  $this->re=$re;
	  
	  if(isset($_GET['start'])){
	  
	    $total=M('buyer')->where($where)->field('money')->select();
		
		$money=0;
		
		foreach($total as $v){
		
		  $money+=$v['money'];
		
		}
	  
	    $this->money=$money;
	  
	  }
	  
	  
	
	  $this->display();
	
	}
	
  
  
  }